package com.shop.controller;

import com.shop.bean.Category;
import com.shop.service.ICategoryService;
import com.shop.util.LayData;
import com.shop.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    @RequestMapping("list")
    @ResponseBody
    public LayData getList(Page page,String text) {
        List<Category> list=categoryService.selectCategories(page, text);
        int count=categoryService.getCount(text);
        return new LayData(count, list);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int delete(int id){
        return categoryService.deleteCategory(id);
    }


    @RequestMapping("getChildren")
    @ResponseBody
    public List<Category> getChildren(int id){
        return categoryService.getChildren(id);
    }


    @RequestMapping("add")
    @ResponseBody
    public int add(Category category){
        return categoryService.addCategory(category);
    }


    @RequestMapping("edit")
    @ResponseBody
    public int edit(Category category){
        return categoryService.editCategory(category);
    }

}
